Start up functions

Read and organize data

read_srm_export <- function(filename, columns = c("peak_name", "RT.min", "basepeak", "area.cpm", "height.cts", "quantitation")) {
  filename %>% 
    # read excel files
    read_excel(sheet = "Integration", skip = 42, 
               col_names = columns, col_types = rep("text", length(columns))) %>% 
    as_data_frame() %>%
    # remove empty rows
    filter(!is.na(peak_name), peak_name != "n.a.") %>% 
    # convert the relevant numeric columns into numbers
    mutate_at(vars(RT.min, area.cpm, height.cts), as.numeric) %>% 
    # remove useless columns
    select(-basepeak, -quantitation) %>% 
    # add filename info
    mutate(file_id = gsub("\\.xls", "", basename(filename))) %>% 
    select(file_id, everything())
}

# get data
all_data <- 
  # find all excel files ##change name and use new folder for new project
  list.files("data_SH1", recursive = TRUE, full.names = TRUE, pattern = "\\.xls$") %>% 
  # send them to the read method
  lapply(read_srm_export) %>% 
  # combine the data set
  bind_rows() %>% 
  # pull out sample information
  #mutate(sample_id = str_match(all_data$file_id, "TSQ\\d+_GB_(.*)$") %>% { .[,2] }) %>% 
  # get n replicates
  group_by(file_id)
  #mutate(n_replicates = length(unique(file_id)))

Calculation peak amounts and rock concentrations, ID standards

depth_and_rock_info <- read_excel(file.path("metadata", "aliphaticSRM_SH1.xlsx")) %>% 
  rename(tle = `TLE.mg`, maltene = `maltenes.mg`, ref_amount_added.ug = `D4.ug` )%>% 
  filter(!is.na(file_id)) %>%
  filter (process == "yes")
depth_and_rock_info
## # A tibble: 68 x 8
##    file_id       OG depth rock.g      tle maltene ref_amount_adde… process
##    <chr>      <dbl> <dbl>  <dbl>    <dbl>   <dbl>            <dbl> <chr>  
##  1 TSQ3481_G…  2.00   125  10.0    24.9     13.7               100 yes    
##  2 TSQ3482_G…  3.00   124  10.1   224        7.30              100 yes    
##  3 TSQ3483_G…  4.00   123  10.3  - 14.4      5.00              100 yes    
##  4 TSQ3484_G…  5.00   122   9.28    3.20     5.40              100 yes    
##  5 TSQ3485_G…  6.00   121  10.6    33.4     NA                 100 yes    
##  6 TSQ3486_G…  7.00   119   9.62 -214        4.80              100 yes    
##  7 TSQ3489_G…  8.00   118   9.70    3.40     5.00              100 yes    
##  8 TSQ3490_G…  9.00   117  10.7     5.00     6.30              100 yes    
##  9 TSQ3491_G… 10.0    115  11.1     5.00     6.00              100 yes    
## 10 TSQ3492_G… 11.0    114  10.2     0.400    6.90              100 yes    
## # ... with 58 more rows
data_by_depth <- 
  all_data %>%
  left_join(depth_and_rock_info, by = "file_id") %>% 
  group_by(file_id) %>% 
  mutate(
    n_peaks = n(),
    n_standards = sum(peak_name == "D4 C29 ISTD"),
    ref_area.cpm = area.cpm[peak_name == "D4 C29 ISTD"],
    amount.ug = area.cpm/ref_area.cpm * ref_amount_added.ug,
   
    #Normalize by what you want
    conc_rock.ug_g = amount.ug / rock.g, 
    conc_tle.ug.g = amount.ug / tle,  
    conc_maltene.ug.g = amount.ug / maltene
    
  )%>% ungroup() %>% 
  arrange(file_id, peak_name) 

data_by_depth
## # A tibble: 11,665 x 19
##    file_id  peak_name  RT.min area.cpm height.cts    OG depth rock.g   tle
##    <chr>    <chr>       <dbl>    <dbl>      <dbl> <dbl> <dbl>  <dbl> <dbl>
##  1 TSQ3466… 20R 4a,24…   34.7    42909     396389  22.0   102   11.0  4.50
##  2 TSQ3466… 20R, 4a M…   33.4    33439     425331  22.0   102   11.0  4.50
##  3 TSQ3466… 20R, 4a M…   32.8    49529     763046  22.0   102   11.0  4.50
##  4 TSQ3466… 20R, 4a,2…   35.3    26212     404760  22.0   102   11.0  4.50
##  5 TSQ3466… 20S, 4a M…   32.1    49207     882869  22.0   102   11.0  4.50
##  6 TSQ3466… 20S, 4a,2…   35.8    31831     268610  22.0   102   11.0  4.50
##  7 TSQ3466… 20S, 4a,2…   34.0    51613     456842  22.0   102   11.0  4.50
##  8 TSQ3466… 25-nor C2…   37.6    11915     155542  22.0   102   11.0  4.50
##  9 TSQ3466… 28, 30 C2…   37.0    27403     343070  22.0   102   11.0  4.50
## 10 TSQ3466… 29, 30 C2…   35.8     5780      63220  22.0   102   11.0  4.50
## # ... with 11,655 more rows, and 10 more variables: maltene <dbl>,
## #   ref_amount_added.ug <dbl>, process <chr>, n_peaks <int>,
## #   n_standards <int>, ref_area.cpm <dbl>, amount.ug <dbl>,
## #   conc_rock.ug_g <dbl>, conc_tle.ug.g <dbl>, conc_maltene.ug.g <dbl>

Calculate Recovery

Linear regressions of the calibration curves

standard <- read_excel(file.path("metadata", "D4_calibration.xlsx"))   ###read excel

###calibration curve
standard %>% 
  ggplot() +
  aes(x = Known.ng, y = Measured_area.counts, color = calibration) + 
  geom_smooth(method = "lm", alpha = 0.5) +
  geom_point() +
  theme_bw() +
  theme(legend.position = "none") 

calibrations <- 
  standard %>% 
  filter(!is.na(calibration)) %>% 
  nest(-calibration) %>% 
  mutate(
    fit = map(data, ~summary(lm(`Measured_area.counts`~ `Known.ng`, data = .x))),
    coefficients = map(fit, "coefficients"),
    intercept = map_dbl(coefficients, `[`, 1, 1),
    intercept_se = map_dbl(coefficients, `[`, 1, 2),
    slope = map_dbl(coefficients, `[`, 2, 1),
    slope_se = map_dbl(coefficients, `[`, 2, 2),
    r2 = map_dbl(fit, "r.squared")
  )

calibrations %>% select(-data, -fit, -coefficients) %>% knitr::kable(d = 3)
calibration intercept intercept_se slope slope_se r2
jan2018 705.862 1371.146 72929.67 3337.256 0.996

Determine yield

These numbers are not useful for anything else.

calib_data <-
  data_by_depth %>% 
  # temp
  mutate(calibration = "jan2018") %>% 
  left_join(calibrations, by = "calibration") %>% 
  mutate(
    total_volume.uL = 100,
    total_inject.uL = 1.5,
    ref_amount_inject_expected.ng = (ref_amount_added.ug * 1000)/total_volume.uL * total_inject.uL ,
    ref_amount_inject_measured.ng = (ref_area.cpm - intercept)/slope,
    ref_amount_measured.ug = ((total_volume.uL* ref_amount_inject_measured.ng)/total_inject.uL) * 1/1000,
    yield = (ref_amount_inject_measured.ng/ref_amount_inject_expected.ng) * 100
  )
  
calib_data
## # A tibble: 11,665 x 34
##    file_id  peak_name  RT.min area.cpm height.cts    OG depth rock.g   tle
##    <chr>    <chr>       <dbl>    <dbl>      <dbl> <dbl> <dbl>  <dbl> <dbl>
##  1 TSQ3466… 20R 4a,24…   34.7    42909     396389  22.0   102   11.0  4.50
##  2 TSQ3466… 20R, 4a M…   33.4    33439     425331  22.0   102   11.0  4.50
##  3 TSQ3466… 20R, 4a M…   32.8    49529     763046  22.0   102   11.0  4.50
##  4 TSQ3466… 20R, 4a,2…   35.3    26212     404760  22.0   102   11.0  4.50
##  5 TSQ3466… 20S, 4a M…   32.1    49207     882869  22.0   102   11.0  4.50
##  6 TSQ3466… 20S, 4a,2…   35.8    31831     268610  22.0   102   11.0  4.50
##  7 TSQ3466… 20S, 4a,2…   34.0    51613     456842  22.0   102   11.0  4.50
##  8 TSQ3466… 25-nor C2…   37.6    11915     155542  22.0   102   11.0  4.50
##  9 TSQ3466… 28, 30 C2…   37.0    27403     343070  22.0   102   11.0  4.50
## 10 TSQ3466… 29, 30 C2…   35.8     5780      63220  22.0   102   11.0  4.50
## # ... with 11,655 more rows, and 25 more variables: maltene <dbl>,
## #   ref_amount_added.ug <dbl>, process <chr>, n_peaks <int>,
## #   n_standards <int>, ref_area.cpm <dbl>, amount.ug <dbl>,
## #   conc_rock.ug_g <dbl>, conc_tle.ug.g <dbl>, conc_maltene.ug.g <dbl>,
## #   calibration <chr>, data <list>, fit <list>, coefficients <list>,
## #   intercept <dbl>, intercept_se <dbl>, slope <dbl>, slope_se <dbl>,
## #   r2 <dbl>, total_volume.uL <dbl>, total_inject.uL <dbl>,
## #   ref_amount_inject_expected.ng <dbl>,
## #   ref_amount_inject_measured.ng <dbl>, ref_amount_measured.ug <dbl>,
## #   yield <dbl>
calib_data %>% 
  select(file_id, peak_name, yield)  %>% 
  arrange(file_id)  %>% 
  unique() %>% 
  ggplot() + aes(file_id, y = yield) +
  geom_point(size = 3) +
  theme_bw() + theme(axis.text.x = element_text(angle = 90, hjust = 0, vjust = 0.5))
## Warning: Removed 2186 rows containing missing values (geom_point).

Ratios

Functions for ratios and sums

sum_peaks <- function(df, filter_condition, new_peak_name) {
  filter_condition <- sprintf("(%s)", str_c(filter_condition, collapse = "|"))
  filter(df, str_detect(peak_name, filter_condition)) %>% 
    summarize(
      file_id = file_id[1],
      depth = depth[1],
      conc_rock.ug_g = sum(conc_rock.ug_g)
    ) %>% 
    mutate(peak_name = new_peak_name)
}

ratio_peaks <- function(df, filter_top, filter_bottom, new_peak_name) {
  filter_top <- sprintf("(%s)", str_c(filter_top, collapse = "|"))
  filter_bottom <- sprintf("(%s)", str_c(filter_bottom, collapse = "|"))
  filter(df, str_detect(peak_name, filter_top) | str_detect(peak_name, filter_bottom)) %>% 
    summarize(
      file_id = file_id[1],
      depth = depth[1],
      ratio = sum(conc_rock.ug_g[str_detect(peak_name, filter_top)]) / sum(conc_rock.ug_g[str_detect(peak_name, filter_bottom)])
    ) %>% 
    mutate(peak_name = new_peak_name)
}

Combine compounds, calculate ratios

#set values to use for later calculations
final_data1 <- calib_data %>% 
    group_by(file_id) %>% 
        do({
          bind_rows(., 
              #C27_Dia/Reg
                sum_peaks(.,  c("C27 aB 20R ST", "C27 aB 20S ST"), "C27Dia"),      
                sum_peaks(., c("C27 aaa 20R ST", "C27 aaa 20S ST", "C27 aBB 20R ST", "C27 aBB 20S ST", "C27 Ba 20R ST", "C27 Ba 20S ST"), "C27Reg"),
            
              #Total Tricyclics
                sum_peaks(., c("C19 Tri HO", "C20 Tri HO", "C21 Tri HO", "C22 Tri HO", "C23 Tri HO", "C24 Tet HO", "C24 Tri HO", "C25 Tri R+S HO", "C26 Tri R HO", "C26 Tri S HO"), "all_tricyclics"),
            
              #4Me_TriMe
                sum_peaks(., c("4B Me 5a cholestane", "4B Me 24 ethyl 5a cholestane", "4B,23S,24S trimethyl 5a cholestane", "4B,23S,24R trimethyl 5a cholestane", "4B,23R,24S trimethyl 5a cholestane", "4B,23R,24R trimethyl 5a cholestane", "4a Me 5a cholestane", "4a Me 24 ethyl 5a cholestane", "4a,23S,24S trimethyl 5a cholestane", "4a,23S,24R trimethyl 5a cholestane", "4a,23R,24S trimethyl 5a cholestane", "4a,23R,24R trimethyl 5a cholestane"), "4Me_TriMe"),
            
              #allRegSt
                sum_peaks(., c("C26 aBB 20S ST", "C26 aBB 20R ST", "C26 aaa 20S ST", "C26 aaa 20R ST","C27 aBB 20S ST", "C27 aBB 20R ST", "C27 aaa 20S ST", "C27 aaa 20R ST", "C28 aBB 20S ST", "C28 aBB 20R ST", "C28 aaa 20S ST", "C28 aaa 20R ST","C29 aBB 20S ST", "C29 aBB 20R ST", "C29 aaa 20S ST", "C29 aaa 20R ST", "C30 aBB 20 R+S ST", "C30 aaa 20S ST", "C30 aaa 20R ST"), "allRegst"),
            
              #allRegHO
                sum_peaks(., c("Ts C27 HO", "Tm C27 HO", "C27 17B H Ho", "29, 30 C28H bisnor HO", "28, 30 C28 bisnor HO", "C29 Ts HO", "C29 Ba HO", "C29 BB Ho", "C30 aB HO", "C30 BB HO", "C30H Ba HO", "C31 HR Ba HO", "C31 aB HR HO", "C31 aB HS HO", "C31 BB HO", "C32 aB HS HO", "C32 aB HR HO", "C33 aB HS HO", "C33 aB HR HO", "C34 aB HR HO", "C34 aB HS HO", "C35 aB HR HO", "C35 aB HS HO"), "allRegHO") ,
              
              #allDiacholestane
              sum_peaks(., c("20S, 4a Me 13B,17a,H diacholestane", "20R, 4a Me 13B,17a,H diacholestane" , "20R, 4a Me 13a,17B,H diacholestane", "20S, 4a,24 dimethyl 13B,17a,H diacholestane", "20R 4a,24 dimethyl 13B,17a,H diacholestane", "20R, 4a,24 dimethyl 13a,17B,H diacholestane" , "20S, 4a,24 dimethyl 13a,17B,H diacholestane", "4a,24 dimethyl 5a cholestane" , "4B,24 dimethyl 5a cholestane"), "allDiacholestane"), 
              
              #all Steranes
              sum_peaks(., c("C26 Ba 20S ST", "C26 Ba 20R ST", "C26 aBB 20S ST", "C26 aBB 20R ST", "C26 aaa 20S ST", "C26 aaa 20R ST", "C27 aaa 20R ST", "C27 aaa 20S ST", "C27 aBB 20R ST", "C27 aBB 20S ST", "C27 Ba 20R ST", "C27 Ba 20S ST", "C28 Ba 20S ST", "C28 Ba 20R ST", "C28 aBB 20S ST", "C28 aBB 20R ST", "C28 aaa 20S ST", "C28 aaa 20R ST" , "C29 Ba 20S ST", "C29 Ba 20R ST", "C29 aBB 20S ST", "C29 aBB 20R ST", "C29 aaa 20S ST", "C29 aaa 20R ST" , "C30 Ba 20S ST", "C30 Ba 20R ST", "C30 aBB 20(R+S) ST", "C30 aaa 20S ST", "C30 aaa 20R ST", "C30 4a Me 20S ST", "C30 4a Me 20R ST + DINO st", "C30 3B Me BB 20S ST", "C30 3B Me 20S ST + C30 3B Me BB 20R ST" , "C30 3BMe 20R ST", "C30 2aMe 20S ST", "C30 2a Me 20R + 4a Me BB 20S ST" , "4B Me 5a cholestane", "4B Me 24 ethyl 5a cholestane", "4B,23S,24S trimethyl 5a cholestane", "4B,23S,24R trimethyl 5a cholestane", "4B,23R,24S trimethyl 5a cholestane", "4B,23R,24R trimethyl 5a cholestane", "4a Me 5a cholestane", "4a Me 24 ethyl 5a cholestane", "4a,23S,24S trimethyl 5a cholestane", "4a,23S,24R trimethyl 5a cholestane", "4a,23R,24S trimethyl 5a cholestane", "4a,23R,24R trimethyl 5a cholestane", "20S, 4a Me 13B,17a,H diacholestane", "20R, 4a Me 13B,17a,H diacholestane" , "20R, 4a Me 13a,17B,H diacholestane", "20S, 4a,24 dimethyl 13B,17a,H diacholestane", "20R 4a,24 dimethyl 13B,17a,H diacholestane", "20R, 4a,24 dimethyl 13a,17B,H diacholestane" , "20S, 4a,24 dimethyl 13a,17B,H diacholestane", "4a,24 dimethyl 5a cholestane" , "4B,24 dimethyl 5a cholestane"), "allSteranes"),
              
              #everything
              sum_peaks(., c(""), "everything")
            
) }) %>% ungroup()
final_data <- final_data1 %>% 
    group_by(file_id) %>% 
        do({
          bind_rows(., 
           #Source
              #C19/tricyclics
                ratio_peaks(., "C19 Tri HO", "all_tricyclics", "C19/tricyclics"),
              #C20/tricyclics
                ratio_peaks(., "C20 Tri HO", "all_tricyclics", "C20/tricyclics"),
              #C21/tricyclics
                ratio_peaks(., "C21 Tri HO", "all_tricyclics", "C21/tricyclics"),
              #C22/tricyclics
                ratio_peaks(., "C22 Tri HO", "all_tricyclics", "C22/tricyclics"),
              #C23/tricyclics
                ratio_peaks(., "C23 Tri HO", "all_tricyclics", "C23/tricyclics"),
              #C24/tricyclics
                ratio_peaks(., c("C24 Tet HO", "C24 Tri HO"), "all_tricyclics", "C24/tricyclics"),
              #C25/tricyclics
                ratio_peaks(., "C25 Tri R+S HO", "all_tricyclics", "C25/tricyclics"),
              #C26/tricyclics
                ratio_peaks(., c("C26 Tri R HO", "C26 Tri S HO"), "all_tricyclics", "C26/tricyclics"),
              #tricyclics/all
                ratio_peaks(., "all_tricyclics", c(""), "tricyclics/all"),
              #C19/C19+23
                ratio_peaks(., "C19 Tri HO", c("C19 Tri HO", "C23 Tri HO"), "C19/C19+23"),
              #C20/C20+23
                ratio_peaks(., "C20 Tri HO", c("C20 Tri HO", "C23 Tri HO"), "C20/C20+23"),
           
              #Ho/St
                ratio_peaks(., "allRegHO", c("C26 aaa 20S ST", "C26 aaa 20R ST", "C27 aaa 20S ST", "C27 aaa 20R ST", "C28 aaa 20S ST", "C28 aaa 20R ST", "C29 aaa 20S ST", "C29 aaa 20R ST", "C30 aaa 20S ST", "C30 aaa 20R ST"), "Ho/St"),
              #Ho/St%
                ratio_peaks(., "allRegHO", c("C26 aaa 20S ST", "C26 aaa 20R ST", "C27 aaa 20S ST", "C27 aaa 20R ST", "C28 aaa 20S ST", "C28 aaa 20R ST", "C29 aaa 20S ST", "C29 aaa 20R ST", "C30 aaa 20S ST", "C30 aaa 20R ST", "allRegHO" ), "Ho/St%"),
            
              #C31_2MHI
                ratio_peaks(., "C31 2a Me Ho", c("C30 aB HO", "C31 2a Me Ho" ), "C31_2MHI"),
              #C31_35_2MHI
                ratio_peaks(., c("C31 2a Me Ho", "C32 2aMe R HO", "C32 2aMe S HO", "C33 2aMe S HO", "C33 2aMe R HO", "C34 2a Me S HO", "C34 2a Me R HO", "C36 2a Me R HO", "C36 2a Me S HO"), c("C30 aB HO", "C31 2a Me Ho", "C32 2aMe R HO", "C32 2aMe S HO", "C33 2aMe S HO", "C33 2aMe R HO", "C34 2a Me S HO", "C34 2a Me R HO", "C36 2a Me R HO", "C36 2a Me S HO"), "C31_35_2MHI"),
              #C31_2-MHI/C27-C30Steranes
                ratio_peaks(., "C31 2a Me Ho", c("C26 aaa 20S ST", "C26 aaa 20R ST", "C27 aaa 20S ST", "C27 aaa 20R ST" ,"C28 aaa 20S ST", "C28 aaa 20R ST", "C29 aaa 20S ST", "C29 aaa 20R ST", "C30 aaa 20S ST", "C30 aaa 20R ST", "C31 2a Me Ho" ), "C31_2-MHI/C27-C30Steranes"),
              #C31 3-MHI 
                ratio_peaks(., "C31 3B Me HO", c("C31 3B Me HO", "C30 aB HO"), "C31 3-MHI"), 
              #C31_35_3MHI(%)
                 ratio_peaks(., c("C31 3B Me HO", "C32 3B Me S HO", "C32 3B Me R HO", "C32 3B Me Ba 22S+R ST", "C33 3BMe S HO", "C33 3BMe R HO", "C34 3B Me S Ho", "C34 3B Me R HO", "C35 3B Me R HO", "C35 3B Me S HO", "C36 3B Me S HO", "C36 3B Me R HO"), c("C30 aB HO","C31 3B Me HO", "C32 3B Me S HO", "C32 3B Me R HO", "C32 3B Me Ba 22S+R ST", "C33 3BMe S HO", "C33 3BMe R HO", "C34 3B Me S HO", "C34 3B Me R HO", "C35 3B Me R HO", "C35 3B Me S HO", "C36 3B Me S HO", "C36 3B Me R HO" ) ,"C31_35_3MHI(%)"),

              #C29ab/C29ab+C30ab
                 ratio_peaks(., "C29 aB HO", c( "C29 aB HO" , "C30 aB HO"), "C29ab/C29ab+C30ab"), 
              #C29ab/allHoab
                 ratio_peaks(., "C29 aB HO" , c("C35 aB HS HO", "C35 aB HR HO", "C34 aB HS HO", "C34 aB HR HO", "C33 aB HS HO" , "C33 aB HR HO", "C32 aB HR HO", "C32 aB HS HO", "C31 aB HS HO", "C31 aB HR HO", "C30 aB HO", "C29 aB HO"), "C29ab/allHoab"), 
              #C30ab/allHoab 
                 ratio_peaks(., "C30 aB HO" , c("C35 aB HS HO", "C35 aB HR HO", "C34 aB HS HO", "C34 aB HR HO", "C33 aB HS HO" , "C33 aB HR HO", "C32 aB HR HO", "C32 aB HS HO", "C31 aB HS HO", "C31 aB HR HO", "C30 aB HO", "C29 aB HO"), "C30ab/allHoab"), 
              #C31ab/allHoab 
                 ratio_peaks(., c("C31 aB HS HO", "C31 aB HR HO") , c("C35 aB HS HO", "C35 aB HR HO", "C34 aB HS HO", "C34 aB HR HO", "C33 aB HS HO" , "C33 aB HR HO", "C32 aB HR HO", "C32 aB HS HO", "C31 aB HS HO", "C31 aB HR HO", "C30 aB HO", "C29 aB HO"), "C31ab/allHoab"),
              #C32ab/allHoab 
                 ratio_peaks(., c("C32 aB HR HO", "C32 aB HS HO") , c("C35 aB HS HO", "C35 aB HR HO", "C34 aB HS HO", "C34 aB HR HO", "C33 aB HS HO" , "C33 aB HR HO", "C32 aB HR HO", "C32 aB HS HO", "C31 aB HS HO", "C31 aB HR HO", "C30 aB HO", "C29 aB HO"), "C32ab/allHoab"),
              #C33ab/allHoab 
                 ratio_peaks(., c( "C33 aB HS HO" , "C33 aB HR HO") , c("C35 aB HS HO", "C35 aB HR HO", "C34 aB HS HO", "C34 aB HR HO", "C33 aB HS HO" , "C33 aB HR HO", "C32 aB HR HO", "C32 aB HS HO", "C31 aB HS HO", "C31 aB HR HO", "C30 aB HO", "C29 aB HO"), "C33ab/allHoab"),
              #C34ab/allHoab 
                 ratio_peaks(., c( "C34 aB HS HO", "C34 aB HR HO") , c("C35 aB HS HO", "C35 aB HR HO", "C34 aB HS HO", "C34 aB HR HO", "C33 aB HS HO" , "C33 aB HR HO", "C32 aB HR HO", "C32 aB HS HO", "C31 aB HS HO", "C31 aB HR HO", "C30 aB HO", "C29 aB HO"), "C34ab/allHoab"),
              #C35ab/allHoab 
                 ratio_peaks(., c("C35 aB HS HO", "C35 aB HR HO") , c("C35 aB HS HO", "C35 aB HR HO", "C34 aB HS HO", "C34 aB HR HO", "C33 aB HS HO" , "C33 aB HR HO", "C32 aB HR HO", "C32 aB HS HO", "C31 aB HS HO", "C31 aB HR HO", "C30 aB HO", "C29 aB HO"), "C35ab/allHoab"),
              #OleananeIndex
                ratio_peaks(., "Oleanane HO", c("Oleanane HO", "C30 aB HO"), "OleananeIndex"),

              #HHI
                ratio_peaks(., c("C35 aB HS HO", "C35 aB HR HO") , c("C35 aB HS HO", "C35 aB HR HO", "C34 aB HS HO", "C34 aB HR HO", "C33 aB HS HO" , "C33 aB HR HO", "C32 aB HR HO", "C32 aB HS HO", "C31 aB HS HO", "C31 aB HR HO"), "HHI"),
              #C35/C35+C34
                ratio_peaks(., c("C35 aB HS HO", "C35 aB HR HO"), c("C34 aB HS HO", "C34 aB HR HO","C35 aB HS HO", "C35 aB HR HO"), "C35/C35+C34"),
              #GI
                ratio_peaks(., "gamma", c("gamma", "C30 aB HO"), "GI"),
              #28,30BNH/28,30BNH+C30
                ratio_peaks(., "28, 30 C28 bisnor HO", c("28, 30 C28 bisnor HO", "C30 aB HO"), "28,30BNH/28,30BNH+C30") ,
           
           #Source
              #C26St/allSt ##INCLUDES ME's
                ratio_peaks(., c("C26 Ba 20S ST", "C26 Ba 20R ST", "C26 aBB 20S ST", "C26 aBB 20R ST", "C26 aaa 20S ST", "C26 aaa 20R ST"), "allSteranes", "C26St/allSt"), 
              #C27St/allSt
                ratio_peaks(., c("C27 aaa 20R ST", "C27 aaa 20S ST", "C27 aBB 20R ST", "C27 aBB 20S ST", "C27 Ba 20R ST", "C27 Ba 20S ST"), "allSteranes", "C27St/allSt"),
              #C28St/allSt
                ratio_peaks(., c("C28 Ba 20S ST", "C28 Ba 20R ST", "C28 aBB 20S ST", "C28 aBB 20R ST", "C28 aaa 20S ST", "C28 aaa 20R ST"), "allSteranes", "C28St/allSt"),
              #C29St/allSt
                ratio_peaks(., c("C29 Ba 20S ST", "C29 Ba 20R ST", "C29 aBB 20S ST", "C29 aBB 20R ST", "C29 aaa 20S ST", "C29 aaa 20R ST"), "allSteranes", "C29St/allSt"),
              #C30St/allSt (does not include Me's in numerator)
                ratio_peaks(., c("C30 Ba 20S ST", "C30 Ba 20R ST", "C30 aBB 20(R+S) ST", "C30 aaa 20S ST", "C30 aaa 20R ST"), "allSteranes", "C30St/allSt"),
              #C30Me/allSt (C30 Me's in numerator)(not in MRM spreadsheet)
                ratio_peaks(., c("C30 4a Me 20S ST", "C30 4a Me 20R ST + DINO st", "C30 3B Me BB 20S ST",  "C30 3B Me 20S ST + C30 3B Me BB 20R ST", "C30 3BMe 20R ST", "C30 2aMe 20S ST", "C30 2a Me 20R + 4a Me BB 20S ST"), "allSteranes", "C30Me/allSt"),
              #DinoSt/allSt
                ratio_peaks(., c("4B Me 5a cholestane", "4B Me 24 ethyl 5a cholestane", "4B,23S,24S trimethyl 5a cholestane", "4B,23S,24R trimethyl 5a cholestane", "4B,23R,24S trimethyl 5a cholestane", "4B,23R,24R trimethyl 5a cholestane", "4a Me 5a cholestane", "4a Me 24 ethyl 5a cholestane", "4a,23S,24S trimethyl 5a cholestane", "4a,23S,24R trimethyl 5a cholestane", "4a,23R,24S trimethyl 5a cholestane", "4a,23R,24R trimethyl 5a cholestane"), "allSteranes", "DinoSt/allSt"),
           
              #C26/(C26-30)aaaSR
                ratio_peaks(., c("C26 aaa 20R ST", "C26 aaa 20S ST"), c("aaa 20R ST", "aaa 20S ST") , "C26/(C26-30)aaaSR"),
              #C27/(C26-30)aaaSR
                ratio_peaks(., c("C27 aaa 20R ST", "C27 aaa 20S ST"), c("aaa 20R ST", "aaa 20S ST") , "C27/(C26-30)aaaSR"),
              #C28/(C26-30)aaaSR
                ratio_peaks(., c("C28 aaa 20R ST", "C28 aaa 20S ST"), c("aaa 20R ST", "aaa 20S ST") , "C28/(C26-30)aaaSR"),
              #C29/(C26-30)aaaSR
                ratio_peaks(., c("C29 aaa 20R ST", "C29 aaa 20S ST"), c("aaa 20R ST", "aaa 20S ST") , "C29/(C26-30)aaaSR"),
              #C30/(C26-30)aaaSR
                ratio_peaks(., c("C30 aaa 20R ST", "C30 aaa 20S ST"), c("aaa 20R ST", "aaa 20S ST") , "C30/(C26-30)aaaSR"),
           
              #C27/C27+C28aaa&abb
                ratio_peaks(., c("C27 aaa 20R ST" , "C27 aaa 20S ST", "C27 aBB 20R ST", "C27 aBB 20S ST"), c("C27 aaa 20R ST" , "C27 aaa 20S ST", "C27 aBB 20R ST", "C27 aBB 20S ST", "C28 aaa 20R ST", "C28 aaa 20S ST", "C28 aBB 20R ST", "C28 aBB 20S ST")  , "C27/C27+C28aaa&abb"),
              #C27/C27+C29aaa&abb
                ratio_peaks(., c("C27 aaa 20R ST" , "C27 aaa 20S ST", "C27 aBB 20R ST", "C27 aBB 20S ST"), c("C27 aaa 20R ST" , "C27 aaa 20S ST", "C27 aBB 20R ST", "C27 aBB 20S ST", "C29 aaa 20R ST", "C29 aaa 20S ST", "C29 aBB 20R ST", "C29 aBB 20S ST")  , "C27/C27+C29aaa&abb"),
              #C28/C28+C27aaa&abb
                ratio_peaks(., c("C28 aaa 20R ST", "C28 aaa 20S ST", "C28 aBB 20R ST", "C28 aBB 20S ST"), c("C27 aaa 20R ST" , "C27 aaa 20S ST", "C27 aBB 20R ST", "C27 aBB 20S ST", "C28 aaa 20R ST", "C28 aaa 20S ST", "C28 aBB 20R ST", "C28 aBB 20S ST")  , "C28/C28+C27aaa&abb"),
              #C28/C28+C29aaa&abb
                ratio_peaks(., c("C28 aaa 20R ST", "C28 aaa 20S ST", "C28 aBB 20R ST", "C28 aBB 20S ST"), c("C29 aaa 20R ST", "C29 aaa 20S ST", "C29 aBB 20R ST", "C29 aBB 20S ST", "C28 aaa 20R ST", "C28 aaa 20S ST", "C28 aBB 20R ST", "C28 aBB 20S ST")  , "C28/C28+C29aaa&abb"),
              #C29/C29+C27aaa&abb
                ratio_peaks(., c("C29 aaa 20R ST", "C29 aaa 20S ST", "C29 aBB 20R ST", "C29 aBB 20S ST"), c("C27 aaa 20R ST" , "C27 aaa 20S ST", "C27 aBB 20R ST", "C27 aBB 20S ST", "C29 aaa 20R ST", "C29 aaa 20S ST", "C29 aBB 20R ST", "C29 aBB 20S ST")  , "C29/C29+C27aaa&abb"),
              #C29/C29+C28aaa&abb
                ratio_peaks(., c("C29 aaa 20R ST", "C29 aaa 20S ST", "C29 aBB 20R ST", "C29 aBB 20S ST"), c("C29 aaa 20R ST", "C29 aaa 20S ST", "C29 aBB 20R ST", "C29 aBB 20S ST", "C28 aaa 20R ST", "C28 aaa 20S ST", "C28 aBB 20R ST", "C28 aBB 20S ST")  , "C29/C29+C28aaa&abb"),
              
              #4Me_TriMe/Me_C26St
                ratio_peaks(., c("4Me_TriMe"), c("4Me_TriMe", "C26 aBB 20S ST", "C26 aBB 20R ST", "C26 aaa 20S ST", "C26 aaa 20R ST") , "4Me_TriMe/Me_C26St"),
              #4Me_TriMe/Me_C27St
                ratio_peaks(., c("4Me_TriMe"), c("4Me_TriMe", "C27 aBB 20S ST", "C27 aBB 20R ST", "C27 aaa 20S ST", "C27 aaa 20R ST") , "4Me_TriMe/Me_C27St"),
              #4Me_TriMe/Me_C28St
                ratio_peaks(., c("4Me_TriMe"), c("4Me_TriMe", "C28 aBB 20S ST", "C28 aBB 20R ST", "C28 aaa 20S ST", "C28 aaa 20R ST") , "4Me_TriMe/Me_C28St"),
              #4Me_TriMe/Me_C29St
                ratio_peaks(., c("4Me_TriMe"), c("4Me_TriMe", "C29 aBB 20S ST", "C29 aBB 20R ST", "C29 aaa 20S ST", "C29 aaa 20R ST") , "4Me_TriMe/Me_C29St"),
              #4Me_TriMe/Me_C30St
                ratio_peaks(., c("4Me_TriMe"), c("4Me_TriMe", "C30 aBB 20 R+S ST", "C30 aaa 20S ST", "C30 aaa 20R ST") , "4Me_TriMe/Me_C30St"),
              #4Me_TriMe/Me_allSt
                ratio_peaks(., c("4Me_TriMe"), c("4Me_TriMe", "allRegst") , "4Me_TriMe/Me_allSt"),
           
              #Dino/all
                ratio_peaks(., "allDiacholestane", c("allSteranes", "allRegHO"), "Dino/all"),
           
              #C26-30St/C26-C30St+regHo 
                ratio_peaks(., c("allRegst"), c("allRegst", "Ts C27 HO", "Tm C27 HO", "C27 17B HO", "29, 30 C28 bisnor HO", "28, 30 C28 bisnor HO", "C29 Ts HO", "C29 Ba HO", "C29 BB Ho", "C30 aB HO", "C30 BB HO", "C30H Ba HO", "C31 HR Ba HO", "C31 aB HR HO", "C31 aB HS HO", "C31 BB HO", "C32 aB HS HO", "C32 aB HR HO", "C33 aB HS HO", "C33 aB HR HO", "C34 aB HR HO", "C34 aB HS HO", "C35 aB HR HO", "C35 aB HS HO"), "C26-30St/C26-C30St_regHo"),
              #C27-C30aaaSt/C27-C30aaaSt+regHo
                ratio_peaks(., c( "C26 aaa 20S ST", "C26 aaa 20R ST", "C27 aaa 20S ST", "C27 aaa 20R ST", "C28 aaa 20S ST", "C28 aaa 20R ST", "C29 aaa 20S ST", "C29 aaa 20R ST", "C30 aaa 20S ST", "C30 aaa 20R ST"), c("C26 aaa 20S ST", "C26 aaa 20R ST", "C27 aaa 20S ST", "C27 aaa 20R ST", "C28 aaa 20S ST", "C28 aaa 20R ST", "C29 aaa 20S ST", "C29 aaa 20R ST", "C30 aaa 20S ST", "C30 aaa 20R ST", "allRegHO"), "C27-C30aaaSt/C27-C30aaaSt+regHo"),
              #Ho/St
                ratio_peaks(., "allRegHO", c("C26 aaa 20S ST", "C26 aaa 20R ST", "C27 aaa 20S ST", "C27 aaa 20R ST", "C28 aaa 20S ST", "C28 aaa 20R ST", "C29 aaa 20S ST", "C29 aaa 20R ST", "C30 aaa 20S ST", "C30 aaa 20R ST"), "Ho/St"),
              #Ho/St%
                ratio_peaks(., "allRegHO", c("C26 aaa 20S ST", "C26 aaa 20R ST", "C27 aaa 20S ST", "C27 aaa 20R ST", "C28 aaa 20S ST", "C28 aaa 20R ST", "C29 aaa 20S ST", "C29 aaa 20R ST", "C30 aaa 20S ST", "C30 aaa 20R ST", "allRegHO" ), "Ho/St%"),
            
              #C31_2MHI
                ratio_peaks(., "C31 2a Me Ho", c("C30 aB HO", "C31 2a Me Ho" ), "C31_2MHI"),
              #C31_35_2MHI
                ratio_peaks(., c("C31 2a Me Ho", "C32 2aMe R HO", "C32 2aMe S HO", "C33 2aMe S HO", "C33 2aMe R HO", "C34 2a Me S HO", "C34 2a Me R HO", "C36 2a Me R HO", "C36 2a Me S HO"), c("C30 aB HO", "C31 2a Me Ho", "C32 2aMe R HO", "C32 2aMe S HO", "C33 2aMe S HO", "C33 2aMe R HO", "C34 2a Me S HO", "C34 2a Me R HO", "C36 2a Me R HO", "C36 2a Me S HO"), "C31_35_2MHI"),
              #C31_2-MHI/C27-C30Steranes
                ratio_peaks(., "C31 2a Me Ho", c("C26 aaa 20S ST", "C26 aaa 20R ST", "C27 aaa 20S ST", "C27 aaa 20R ST" ,"C28 aaa 20S ST", "C28 aaa 20R ST", "C29 aaa 20S ST", "C29 aaa 20R ST", "C30 aaa 20S ST", "C30 aaa 20R ST", "C31 2a Me Ho" ), "C31_2-MHI/C27-C30Steranes"),
           
            #Thermal Maturity
              #C27_Dia/Reg
                ratio_peaks(., "C27Dia", "C27Reg", "C27Dia/Reg"),
              #C27Dia_S/R
                ratio_peaks(., "C27 aB 20S ST", "C27 aB 20R ST", "C27Dia_S/R"),
              #C27Dia_S/S+R
                ratio_peaks(., "C27 aB 20S ST", c("C27 aB 20S ST", "C27 aB 20R ST"), "C27Dia_S/S+R") ,
              #C27Reg_abb/all 
                 ratio_peaks(., c("C27 aBB 20R ST", "C27 aBB 20S ST"), c("C27 aaa 20R ST", "C27 aaa 20S ST", "C27 aBB 20R ST", "C27 aBB 20S ST"), "C27Reg_abb/aaa"),
              #C27RegaaaS/S+R
                ratio_peaks(., "C27 aaa 20S ST", c("C27 aaa 20R ST", "C27 aaa 20S ST"), "C27Regaaa_S/S+R"), 
              #C27RegabbS/S+R
                ratio_peaks(., "C27 aBB 20S ST", c("C27 aBB 20S ST", "C27 aBB 20R ST"), "C27Regabb_S/S+R"),
              #C28Dia/all
                ratio_peaks(., c("C28 Ba 20S ST", "C28 Ba 20R ST"), c("C28 aBB 20S ST", "C28 aBB 20R ST", "C28 aaa 20S ST", "C28 aaa 20R ST", "C28 Ba 20S ST", "C28 Ba 20R ST"), "C28Dia/all"),
              #C28DiaS/S+R
                ratio_peaks(., "C28 Ba 20S ST", c("C28 Ba 20S ST", "C28 Ba 20R ST"), "C28DiaS/S+R"),
              #C28abb/all
                ratio_peaks(., c("C28 aBB 20S ST", "C28 aBB 20R ST"), c("C28 aBB 20S ST", "C28 aBB 20R ST", "C28 aaa 20S ST", "C28 aaa 20R ST"), "C28abb/all"),
              #C28aaaS/S+R
                ratio_peaks(., "C28 aaa 20S ST", c("C28 aaa 20S ST", "C28 aaa 20R ST"), "C28aaaS/S+R"),
              #C28abbS/S+R
                ratio_peaks(., "C28 aBB 20S ST", c("C28 aBB 20S ST", "C28 aBB 20R ST"), "C28abbS/S+R"),
              #C29Dia/all
                ratio_peaks(., c("C29 Ba 20S ST", "C29 Ba 20R ST"),  c("C29 Ba 20S ST", "C29 Ba 20R ST", "C29 aBB 20S ST", "C29 aBB 20R ST", "C29 aaa 20S ST", "C29 aaa 20R ST"), "C29Dia/all"),
              #C29DiaS/S+R
                ratio_peaks(., "C29 Ba 20S ST", c("C29 Ba 20S ST", "C29 Ba 20R ST"), "C29DiaS/S+R"),
              #C29abb/all
                ratio_peaks(., c("C29 aBB 20S ST", "C29 aBB 20R ST"), c( "C29 aaa 20S ST", "C29 aaa 20R ST", "C29 aBB 20S ST", "C29 aBB 20R ST" ), "C29abb/all"),
              #C29aaaS/S+R
                ratio_peaks(., "C29 aaa 20S ST", c("C29 aaa 20S ST", "C29 aaa 20R ST") , "C29aaaS/S+R"),
              #C29abbS/S+R
                ratio_peaks(., "C29 aBB 20S ST", c("C29 aBB 20S ST", "C29 aBB 20R ST"), "C29abbS/S+R"),
              #C27Ts/Ts+Tm
                ratio_peaks(., "Ts C27 HO", c("Ts C27 HO", "Tm C27  HO"), "C27Ts/Tm"),
              #C28BNH29,30/28,30
                ratio_peaks(., "29, 30 C28 bisnor HO", c("29, 30 C28 bisnor HO", "28, 30 C28 bisnor HO"), "C28BNH29,30/28,30"),
              #C29Ts/Ts+ab
                ratio_peaks(., "C29 Ts HO", c( "C29 aB HO", "C29 Ts HO"), "C29Ts/ab"),
              #C29ba/ba+ab
                ratio_peaks(.,"C29 Ba HO",  c("C29 aB HO", "C29 Ba HO"), "C29ba/ab"),
              #C29bb/bb+ab
                ratio_peaks(., "C29 BB Ho", c("C29 BB Ho", "C29 aB HO"), "C29bb/ab"),
              #C30_30nor/30nor+ab
                ratio_peaks(., "30-nor C30H HO", c("C30 aB HO", "30-nor C30H HO"),  "C30_30nor/ab"),
              #C30ba/ba+ab
                ratio_peaks(., "C30H Ba HO", c("C30 aB HO", "C30H Ba HO"), "C30ba/ab"),
              #C30bb/bb+ab
                ratio_peaks(., "C30 BB HO", c("C30 aB HO", "C30 BB HO"), "C30bb/ab"),
              #C31S/S+R
                ratio_peaks(., "C31 aB HS  HO", c("C31 aB HR HO", "C31 aB HS  HO"), "C31S/S+R"),
              #C32S/S+R
                ratio_peaks(., "C32 aB HS HO", c("C32 aB HS HO", "C32 aB HR HO"), "C32S/S+R"),
              #C33S/S+R
                ratio_peaks(., "C33 aB HS HO", c("C33 aB HS HO", "C33 aB HR HO"), "C33S/S+R"),
              #C34S/S+R
                ratio_peaks(., "C34 aB HS HO", c("C34 aB HS HO", "C34 aB HR HO") , "C34S/S+R"),
              #C35S/S+R
                ratio_peaks(., "C35 aB HS HO", c("C35 aB HS HO", "C35 aB HR HO") , "C35S/S+R")
      
 ) }) %>% ungroup() 
  
final_data
## # A tibble: 19,947 x 35
##    file_id  peak_name  RT.min area.cpm height.cts    OG depth rock.g   tle
##    <chr>    <chr>       <dbl>    <dbl>      <dbl> <dbl> <dbl>  <dbl> <dbl>
##  1 TSQ3466… 20R 4a,24…   34.7    42909     396389  22.0   102   11.0  4.50
##  2 TSQ3466… 20R, 4a M…   33.4    33439     425331  22.0   102   11.0  4.50
##  3 TSQ3466… 20R, 4a M…   32.8    49529     763046  22.0   102   11.0  4.50
##  4 TSQ3466… 20R, 4a,2…   35.3    26212     404760  22.0   102   11.0  4.50
##  5 TSQ3466… 20S, 4a M…   32.1    49207     882869  22.0   102   11.0  4.50
##  6 TSQ3466… 20S, 4a,2…   35.8    31831     268610  22.0   102   11.0  4.50
##  7 TSQ3466… 20S, 4a,2…   34.0    51613     456842  22.0   102   11.0  4.50
##  8 TSQ3466… 25-nor C2…   37.6    11915     155542  22.0   102   11.0  4.50
##  9 TSQ3466… 28, 30 C2…   37.0    27403     343070  22.0   102   11.0  4.50
## 10 TSQ3466… 29, 30 C2…   35.8     5780      63220  22.0   102   11.0  4.50
## # ... with 19,937 more rows, and 26 more variables: maltene <dbl>,
## #   ref_amount_added.ug <dbl>, process <chr>, n_peaks <int>,
## #   n_standards <int>, ref_area.cpm <dbl>, amount.ug <dbl>,
## #   conc_rock.ug_g <dbl>, conc_tle.ug.g <dbl>, conc_maltene.ug.g <dbl>,
## #   calibration <chr>, data <list>, fit <list>, coefficients <list>,
## #   intercept <dbl>, intercept_se <dbl>, slope <dbl>, slope_se <dbl>,
## #   r2 <dbl>, total_volume.uL <dbl>, total_inject.uL <dbl>,
## #   ref_amount_inject_expected.ng <dbl>,
## #   ref_amount_inject_measured.ng <dbl>, ref_amount_measured.ug <dbl>,
## #   yield <dbl>, ratio <dbl>

Bring in other data for comparison (data from Jones et al., (2018))

osisotope <- read_excel(file.path("metadata", "SH1_Osi_forGarrett.xlsx")) %>% 
  rename(depth = `Depth (m)`) 
cisotope <- read_excel(file.path("metadata", "Appendix_Table1_geochemistry.xlsx")) %>% 
  #rename columns
  rename(depth = `Abs. depth (m)` , d13c_org = `Average δ13Corg (‰ VPDB)` , carb = `%Carbonate`, TOC = `%TOC`, d13c_carb = `Average δ13Ccarb (‰ VPDB)`) %>%
  #remove columns not of interest
  select(-`stdev δ13Corg`, -`δ13Ccarb stdev`, -`d18O-avg`, -`d18O stdev`, -`∆13C`, -`d13c_carb`)

cisotope
## # A tibble: 146 x 4
##    depth d13c_org  carb   TOC
##    <dbl>    <dbl> <dbl> <dbl>
##  1   125    -25.6  7.80 1.04 
##  2   125    -26.0 13.7  0.835
##  3   125    -25.3 16.1  0.874
##  4   124    -25.5 17.2  1.02 
##  5   124    -25.4 10.1  1.05 
##  6   124    -25.2 11.4  1.13 
##  7   124    -25.2 13.9  1.27 
##  8   124    -25.1 16.5  1.58 
##  9   123    -25.2 15.6  1.52 
## 10   123    -25.3 23.0  0.502
## # ... with 136 more rows
horizontal_lines <-
  data_frame(
    depth = c(123, 120, 117)
  )

carb <- cisotope %>%
  ggplot() +
  aes(depth, carb) +
  geom_point() +
  geom_line() +
  scale_x_reverse() +
  coord_flip() +
  ggtitle("carbonate%") + 
  geom_vline(horizontal_lines,
             mapping = aes(xintercept = depth)) 


TOC <- cisotope %>%
  ggplot() +
  aes(depth, TOC) +
  geom_point() +
  geom_line() +
  scale_x_reverse() +
  coord_flip() +
  ggtitle("TOC%") +
  theme(axis.text.y = element_blank(), 
            axis.ticks.y = element_blank(), 
            axis.title.y = element_blank()) + 
  geom_vline(horizontal_lines,
             mapping = aes(xintercept = depth))


d13c <- cisotope %>%
  ggplot() +
  aes(depth, d13c_org) +
  geom_point() +
  geom_line() +
  scale_x_reverse() +
  coord_flip() +
  ggtitle("d13C_org") +
  theme(axis.text.y = element_blank(), 
            axis.ticks.y = element_blank(), 
            axis.title.y = element_blank()) + 
   geom_vline(horizontal_lines,
             mapping = aes(xintercept = depth))

os <- osisotope %>%
  ggplot() +
  aes(x = depth, y = Osi) +
  geom_point() +
  geom_line() +
  #facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip() +
  ggtitle("os") +
  #theme(axis.text.y = element_blank(), 
            #axis.ticks.y = element_blank(), 
            #axis.title.y = element_blank()) + 
  geom_vline(horizontal_lines,
             mapping = aes(xintercept = depth))

#ggplotly(carb) 
#ggplotly(TOC)
#ggplotly(d13c)

library(gridExtra)
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
grid.arrange(carb, TOC, d13c, os, ncol=4)
## Warning: Removed 3 rows containing missing values (geom_point).

Plot against depth

Sterane - Source

Regular steranes over all steranes

sterane_area <- subset(final_data, peak_name %in% c("C26St/allSt", "C27St/allSt", "C28St/allSt", "C29St/allSt", "C30St/allSt", "C30Me/allSt", "DinoSt/allSt")) %>%
  ggplot() +
  geom_area(mapping = aes(fill = peak_name)) +
  aes(x = depth, y = ratio, color = peak_name) +
  #facet_grid(~peak_name, scales = "free") +
  coord_flip() +
  scale_x_reverse() +
  scale_y_continuous() 

ggplotly(sterane_area)
## Warning: Removed 112 rows containing missing values (position_stack).
#sterane_area_all <- grid.arrange(carb, TOC, d13c, os, sterane_area, ncol=5) 

Regular aaa steranes / all regular aaa steranes

regaaa <- subset(final_data, peak_name %in% c("C26/(C26-30)aaaSR","C27/(C26-30)aaaSR", "C28/(C26-30)aaaSR", "C29/(C26-30)aaaSR", "C30/(C26-30)aaaSR")) %>%
  ggplot() +
  geom_area(mapping = aes(fill = peak_name)) +
  aes(x = depth, y = ratio, color = peak_name) +
  #facet_wrap(~peak_name, scales = "free") +
  coord_flip() +
  scale_x_reverse() +
  scale_y_continuous()  
  #theme(axis.text.y = element_blank(), 
           # axis.ticks.y = element_blank(), 
           # axis.title.y = element_blank())

ggplotly(regaaa)
## Warning: Removed 80 rows containing missing values (position_stack).
#reaaa_all <- grid.arrange(d13c, regaaa, ncol=2)

aaa&abb

aaa <- subset(final_data, peak_name %in% c("C27/C27+C28aaa&abb", "C27/C27+C29aaa&abb", "C28/C28+C27aaa&abb", "C28/C28+C29aaa&abb", "C29/C29+C27aaa&abb", "C29/C29+C28aaa&abb")) %>%
  ggplot() +
  geom_point() +
  geom_line() +
  #geom_area(mapping = aes(fill = peak_name)) +
  aes(x = depth, y = ratio, color = peak_name) +
  facet_grid(~peak_name) +
  coord_flip() +
  scale_x_reverse() +
  scale_y_continuous()  
  

ggplotly(aaa)
#reaaa_all <- grid.arrange( d13c, aaa, ncol=7)

4Me_TriMes

TriMe <- subset(final_data, peak_name %in% c("4Me_TriMe/Me_C26St", "4Me_TriMe/Me_C27St", "4Me_TriMe/Me_C28St", "4Me_TriMe/Me_C29St", "4Me_TriMe/Me_C30St", "4Me_TriMe/Me_allSt")) %>%
  ggplot() +
  geom_point() +
  geom_line() +
  #geom_area(mapping = aes(fill = peak_name)) +
  aes(x = depth, y = ratio, color = peak_name) +
  facet_grid(~peak_name) +
  coord_flip() +
  scale_x_reverse() 
ggplotly(TriMe)

Sterane over all ratios

yet <- subset(final_data, peak_name %in% c("C26-30St/C26-C30St_regHo", "C27-C30aaaSt/C27-C30aaaSt+regHo")) %>%
  ggplot() +
  aes(x = depth, y = ratio, color = peak_name) +
  geom_point() +
  geom_line() +
  facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
ggplotly(yet)

Hopanes - Source

Tricyclics

tri <- subset(final_data, peak_name %in% c("C19/tricyclics" , "C20/tricyclics" , "C21/tricyclics" , "C22/tricyclics" , "C23/tricyclics" , "C24/tricyclics" , "C25/tricyclics" , "C26/tricyclics")) %>%
  ggplot() +
  geom_area(mapping = aes(fill = peak_name)) +
  aes(x = depth, y = ratio, color = peak_name) +
  #facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
  
ggplotly(tri)
## Warning: Removed 128 rows containing missing values (position_stack).
tri_all <- subset(final_data, peak_name %in% c("C19/C19+23",  "C20/C20+23", "tricyclics/all")) %>%
  ggplot() +
  aes(x = depth, y = ratio) +
  geom_point() +
  geom_smooth() +
  facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
ggplotly(tri_all)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 48 rows containing non-finite values (stat_smooth).

Hopanes over steranes

vertical_lines <- data_frame(
    one = 1
  )

host <- subset(final_data, peak_name == "Ho/St") %>%
  ggplot() +
  aes(x = depth, y = ratio) +
  geom_point() +
  geom_line() +
  facet_wrap(~peak_name, scales = "free") +
  geom_hline(vertical_lines,
             mapping = aes(yintercept = one)) +
  scale_x_reverse() +
  coord_flip() 
  

ggplotly(host)

2Me Hopanes

mehi <- subset(final_data, peak_name %in% c("C31_2MHI", "C31_35_2MHI", "C31_2-MHI/C27-C30Steranes"))%>%
  ggplot() +
  aes(x = depth, y = ratio, color = peak_name) +
  geom_point() +
  geom_line() +
  facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
ggplotly(mehi)

3Me Hopanes

threemehi <- subset(final_data, peak_name %in% c( "C31_35_3MHI(%)", "C31 3-MHI")) %>%
  ggplot() +
  aes(x = depth, y = ratio) +
  geom_point() +
  geom_smooth() +
  facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
ggplotly(threemehi)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 32 rows containing non-finite values (stat_smooth).

C29 aB Hopane

abs <- subset(final_data, peak_name%in% c("C29ab/allHoab", "C29ab/C29ab+C30ab")) %>%
  filter(ratio > 0.1) %>%
  ggplot() +
  aes(x = depth, y = ratio) +
  geom_point() +
  geom_smooth() +
  facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
ggplotly(abs)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

ab/all ho

ho <- subset(final_data, peak_name %in% c("C29ab/allHoab","C30ab/allHoab", "C31ab/allHoab", "C32ab/allHoab", "C33ab/allHoab", "C34ab/allHoab", "C35ab/allHoab")) %>%
   ggplot() +
  geom_area(mapping = aes(fill = peak_name)) +
  aes(x = depth, y = ratio, color = peak_name) +
  #facet_wrap(~peak_name, scales = "free") +
  coord_flip() +
  scale_x_reverse() +
  scale_y_continuous() 
ggplotly(ho)
## Warning: Removed 112 rows containing missing values (position_stack).

Stratification

HHIGI <- subset(final_data, peak_name %in% c( "GI", "HHI")) %>%
  ggplot() +
  aes(x = depth, y = ratio) +
  geom_point() +
  geom_line() +
  facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
ggplotly(HHIGI)

Miscelaneous Hopane ratios

subset(final_data, peak_name== "OleananeIndex") %>%
  ggplot() +
  aes(x = depth, y = ratio) +
  geom_point() +
  geom_line() +
 # facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
## Warning: Removed 16 rows containing missing values (geom_point).
## Warning: Removed 16 rows containing missing values (geom_path).

subset(final_data, peak_name== "C35/C35+C34") %>%
  ggplot() +
  aes(x = depth, y = ratio) +
  geom_point() +
  geom_line() +
  facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
## Warning: Removed 16 rows containing missing values (geom_point).
## Warning: Removed 16 rows containing missing values (geom_path).

subset(final_data, peak_name== "28,30BNH/28,30BNH+C30") %>%
  ggplot() +
  aes(x = depth, y = ratio) +
  geom_point() +
  geom_line()+
  facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
## Warning: Removed 16 rows containing missing values (geom_point).
## Warning: Removed 16 rows containing missing values (geom_path).

Thermal Maturity

C27Dia/Reg

dia <- subset(final_data, peak_name == "C27Dia/Reg") %>%
  ggplot() +
  aes(x = depth, y = ratio) +
  geom_point() +
  geom_smooth() +
  facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()

ggplotly(dia)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 16 rows containing non-finite values (stat_smooth).

DiaS/S+R

diasr <- subset(final_data, peak_name%in% c("C28DiaS/S+R" , "C29DiaS/S+R")) %>%
  filter(depth != 116.490) %>% filter(depth != 116.900) %>%
  ggplot() +
  aes(x = depth, y = ratio, color = peak_name) +
  geom_point() +
  geom_line() +
  #facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()

ggplotly(diasr)

C27Regabb/aaa

twentyseven<- subset(final_data, peak_name== "C27Reg_abb/aaa") %>%
  filter(depth != 115.885) %>%
  ggplot() +
  aes(x = depth, y = ratio) +
  geom_line() +
  geom_point() +
  facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()

ggplotly(twentyseven)

aaa_S/S+R

aaa<- final_data %>%
  filter(peak_name %in% c("C27Regaaa_S/S+R", "C28aaaS/S+R", "C29aaaS/S+R")) %>%
  filter(depth != 115.885) %>%
  ggplot() +
  aes(x = depth, y = ratio, color = peak_name) +
  geom_line() +
  geom_point() +
  facet_grid(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()

ggplotly(aaa)

abb_s/s+r

abb <- subset(final_data, peak_name %in% c("C27Regabb_S/S+R", "C28abbS/S+R", "C29abbS/S+R")) %>%
  filter(depth != 115.885) %>%
  ggplot() +
  aes(x = depth, y = ratio, color = peak_name) +
  geom_point() +
  #facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()

ggplotly(abb)

C28/9Dia/all

Dia <- subset(final_data, peak_name %in% c("C28Dia/all", "C29Dia/all")) %>%
  ggplot() +
  aes(x = depth, y = ratio, color = peak_name) +
  geom_point() +
  geom_line() +
  #facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()

ggplotly(Dia)

C28/9abb/all

eightnine <- subset(final_data, peak_name %in% c("C28abb/all", "C29abb/all"))  %>%
  filter(depth != 115.885) %>%
  ggplot() +
  aes(x = depth, y = ratio, color = peak_name) +
  geom_point() +
  geom_line() +
  #facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip() 

ggplotly(eightnine)

C27Ts/Tm

tstm <- subset(final_data, peak_name== "C27Ts/Tm") %>%
  filter(depth != 115.885) %>% filter(depth != 120.405) %>%
  ggplot() +
  aes(x = depth, y = ratio) +
  geom_point() +
  geom_line() +
  facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
ggplotly(tstm)

C28BNH29,30/28,30

bnh <- subset(final_data, peak_name== "C28BNH29,30/28,30") %>%
  ggplot() +
  aes(x = depth, y = ratio) +
  geom_point() +
  geom_smooth() +
  facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
ggplotly(bnh)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 17 rows containing non-finite values (stat_smooth).

C29Ts/ab

tsab<- subset(final_data, peak_name== "C29Ts/ab") %>%
  ggplot() +
  aes(x = depth, y = ratio) +
  geom_point() +
  geom_line() +
  facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
ggplotly(tsab)

C29,30ba/ab

baab <- subset(final_data, peak_name %in% c("C29ba/ab", "C30ba/ab")) %>%
  ggplot() +
  aes(x = depth, y = ratio, color = peak_name) +
  geom_point() +
  geom_line() +
  #facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()

ggplotly(baab)

C29bb/ab

bbab <- subset(final_data, peak_name %in% c("C29bb/ab", "C30bb/ab")) %>%
  ggplot() +
  aes(x = depth, y = ratio, color = peak_name) +
  geom_point() +
  geom_line() +
  #facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
ggplotly(bbab)

C30_30nor/ab

thirtynor <- subset(final_data, peak_name== "C30_30nor/ab") %>%
  ggplot() +
  aes(x = depth, y = ratio) +
  geom_point() +
  geom_smooth() +
  facet_wrap(~peak_name, scales = "free") +
  scale_x_reverse() +
  coord_flip()
ggplotly(thirtynor)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 16 rows containing non-finite values (stat_smooth).

C30 ab/ba

thabba <- subset(final_data, peak_name %in% c("C30 aB HO", "C30H Ba HO")) %>%
  ggplot() +
  aes(x = depth, y = conc_rock.ug_g, color = peak_name) +
  geom_point() + 
  geom_line() +
  #facet_wrap(~peak_name) +
  scale_x_reverse() +
  coord_flip()
ggplotly(thabba)

All Ho S/R

srho <- final_data %>%
  filter(peak_name %in% c("C31S/S+R", "C32S/S+R", "C33S/S+R", "C34S/S+R", "C35S/S+R")) %>%
  filter(ratio > 0.1) %>%
  ggplot() +
  aes(x = depth, y = ratio, color = peak_name) +
  geom_point() +
  geom_line() +
  #facet_grid(~peak_name) +
  scale_x_reverse() +
  coord_flip()
ggplotly(srho)

Everything

erry <- final_data %>%
  filter(peak_name == "everything") %>%
  ggplot() +
  aes(x = depth, y = conc_rock.ug_g) +
  geom_point() +
  geom_line() +
  #facet_grid(~peak_name) +
  scale_x_reverse() +
  coord_flip()
ggplotly(erry)

Chunk to check plots

outcome <- calib_data %>% 
  group_by(file_id) %>%
  select(file_id, peak_name, depth, area.cpm, conc_rock.ug_g) %>% 
  do({
    bind_rows(., 
            ratio_peaks(., "C27 aB 20S ST", "C27 aB 20R ST", "C27Dia_S/R")
    )
  }) %>% 
  filter(#!str_detect(file_id, "TSQ3779"),  
         str_detect(peak_name, "C27 aB 20R ST")) 
         #str_detect(peak_name, "aB"))
outcome
## # A tibble: 82 x 6
## # Groups:   file_id [82]
##    file_id          peak_name     depth area.cpm conc_rock.ug_g ratio
##    <chr>            <chr>         <dbl>    <dbl>          <dbl> <dbl>
##  1 TSQ3466_GB_OG022 C27 aB 20R ST 102      24465          9.08     NA
##  2 TSQ3467_GB_OG023 C27 aB 20R ST 101      30269         11.6      NA
##  3 TSQ3468_GB_OG025 C27 aB 20R ST  98.9    38685         15.1      NA
##  4 TSQ3469_GB_OG026 C27 aB 20R ST  98.1     2625          1.89     NA
##  5 TSQ3472_GB_OG027 C27 aB 20R ST  96.9     4195          1.62     NA
##  6 TSQ3473_GB_OG019 C27 aB 20R ST 105        651          0.416    NA
##  7 TSQ3474_GB_OG020 C27 aB 20R ST 104       1537          0.852    NA
##  8 TSQ3475_GB_OG021 C27 aB 20R ST 103       7266          3.40     NA
##  9 TSQ3476_GB_OG018 C27 aB 20R ST 106       3130          1.06     NA
## 10 TSQ3481_GB_OG002 C27 aB 20R ST 125       1423          0.494    NA
## # ... with 72 more rows